﻿CREATE PROCEDURE [dbo].[proc_MarketProjectItem_Sum]
(
	@USERID VARCHAR(20),
	@MID VARCHAR(20),
	@ItemName VARCHAR(50)
)

AS
DECLARE @str VARCHAR(MAX)

BEGIN
SET @str= ' SELECT SUM('+@ItemName+') FROM MarketProjectItem mpi JOIN ProT_ClassT3 pct3 ON mpi.T3=pct3.id '
SET @str= @str+' WHERE [MID]='+@MID
IF @USERID!=0
	SET @str=@str+' AND [USERID]='+@USERID

EXEC(@str)

	SET NOCOUNT ON;
SELECT @str

END
